<template>
	<view class="">
		<u-modal :show="show" cancelColor="#555" confirmColor="#1BA95B" :showCancelButton="true" :title="title"
			@cancel="show=false" @confirm="confirm"></u-modal>
		<view class="margin_top1 ffffff mainpadding">
			<view class="xiahuaxian flexbetween" @click="jumpurl('/pages_mypage/zhifubbd')">
				<view class="ershiba nofonweight xiaohei">支付宝信息</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class="xiahuaxian flexbetween margin_top">
				<view class="ershiba nofonweight xiaohei">当前版本</view>
				<view class="ershiba nofonweight xiaohei">{{version}}</view>
			</view>
			<view class="xiahuaxian flexbetween margin_top" @click="jumpurl('/pages/system/system?type=1')">
				<view class="ershiba nofonweight xiaohei">用户协议</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class="xiahuaxian flexbetween margin_top" @click="jumpurl('/pages/system/system?type=3')">
				<view class="ershiba nofonweight xiaohei">关于我们</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class=" flexbetween xiahuaxian margin_top" @click="jumpurl('/pages/system/system?type=2')">
				<view class="ershiba nofonweight xiaohei">隐私协议</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class=" flexbetween margin_top xiahuaxian">
				<view class="ershiba nofonweight xiaohei">占用内存</view>
				<view class="ershiba nofonweight xiaohei margin_right2">{{fileSizeString}}</view>
			</view>
			<view class=" flexbetween margin_top" @click="zxshow=true">
				<view class="ershiba nofonweight xiaohei">注销账号</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<view class="ffffff mainpadding margin_top1 flexcenter" @click="title='确定清楚所有缓存吗？';show = true;">
			<view class="ershiba nofonweight xiaohei">清除缓存</view>
		</view>
		<view class="ffffff mainpadding margin_top1 flexcenter" @click="title='确定要退出当前账户么？';show = true">
			<view class="ershiba nofonweight xiaohei">退出登录</view>
		</view>
		<u-modal title='警告' :show="zxshow" content="账号注销后，您的系统数据将不再可用。请慎重处理!!!" @confirm="zxconfirm" style='text-align: center;' confirmColor="#999"
			confirmText="确认注销" cancelText="再想想" cancelColor="#2361FF" buttonReverse showCancelButton
			@cancel='zxshow=false'></u-modal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				title: '确定要退出当前账户么？',
				version: "",
				fileSizeString:"",
				zxshow:false
			}
		},
		onLoad() {
			let that = this
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
				console.log(widgetInfo, "888");
				that.version = widgetInfo.version
			});
			// #endif
			// #ifdef MP-WEIXIN
			uni.getSystemInfo({
				success: function(res) {
					that.version = res.appVersion
				}
			})
			// #endif
			this.formatSize()
		},
		methods: {
			zxconfirm() {
				this.zxshow = false;
				httpRequest.request('/api/user/zxUser', 'POST', {
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					if(res.code==1){
						uni.clearStorageSync();
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})
			},
			formatSize() {
				let that = this;
				uni.getStorageInfo({
					success(res) {
						let size = res.currentSize;
						if (size < 1024) {
							that.fileSizeString = size + ' B';
						} else if (size/1024>=1 && size/1024/1024<1) {
							that.fileSizeString = Math.floor(size/1024*100)/100 + ' KB';
						} else if (size/1024/1024>=1) {
							that.fileSizeString = Math.floor(size/1024/1024*100)/100 + ' M';
						}
					}
				})
			},
			// 清楚缓存
			clearCache() {
				let that = this;
				 uni.clearStorageSync();
				//重新获取并显示清除后的缓存大小
				httpRequest.toast("清除成功")
				setTimeout(() => {
					uni.navigateBack(1)
				}, 1000)
			},
			confirm() {
				this.show = false;
				if(this.title == "确定清楚所有缓存吗？"){
					this.clearCache()
					return false
				}
				// 将存储的数据改为空达到退出登录的效果
				uni.clearStorageSync();
				httpRequest.toast("退出登录成功")
				setTimeout(() => {
					uni.navigateBack(1)
				}, 1000)
			},
			jumpurl(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #F9F9F9;
	}
</style>